#ifndef X11PLAYER_H
#define X11PLAYER_H

#include <iostream>
#include <stdlib.h>
#include <stdio.h>

#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <unistd.h>
#include <memory.h>

typedef struct _xRect {
    unsigned int x;
    unsigned int y;
    unsigned int width;
    unsigned int height;
    _xRect() {width = 0; height = 0;}
}xRect;

class X11Player {
public:
    X11Player();
    ~X11Player();

    int init(unsigned int width, unsigned int height, unsigned long wId);
    void close();

public:
    xRect getRect();
    int inputRgb32(unsigned int width, unsigned int height, char* data);
    int inputYuv420p(unsigned int width, unsigned int height, char* data);

private:
    void autoFixedXImage(int width, int height);

private:
    XID _wId;

    Display* _disp;
    GC _gc;
    Visual* _visual;
    int _srcDepth;

    XImage* _image;
    unsigned int _width;
    unsigned int _height;
    unsigned int _image_bpp;

    // 上一次绘画时的 w h
    unsigned int _drawWidth;
    unsigned int _drawHeight;

    // 画面缓存
    char* _imageData;
};

#endif // X11PLAYER_H
